<template>
  <div>
    <el-container>
      <el-aside width="200px">
        <!-- 左侧边栏 
        text--color:字体颜色
        active-text-color:激活的文本颜色
        router：	是否使用 vue-router 的模式，启用该模式会在激活导航时以 index 作为 path 进行路由跳转
        -->
        <el-menu
          default-active="2"
          class="el-menu-vertical-demo"
          text-color="#fff"
          active-text-color="#ffd04b"
          router
        >
          <el-menu-item index="/">
            <i class="el-icon-menu"></i>
            <span slot="title">首页</span>
          </el-menu-item>

          <!-- 动态侧边栏 -->
          <div v-for="item in info.menus" :key="item.id">
            <!-- 有childred -->
            <el-submenu :index="item.id+''" v-if="item.children">
            <template slot="title">
              <i class="item.icon"></i>
              <span>{{item.title}}</span>
            </template>
            <el-menu-item :index="i.url" v-for="i in item.children" :key="i.id">{{i.title}}</el-menu-item>
          </el-submenu>
          <!-- 没有children -->
          <el-menu-item :index="item.url" v-else>
            <i class="el-icon-view"></i>
            <span slot="title">{{item.title}}</span>
          </el-menu-item>
          </div>
        </el-menu>
      </el-aside>
      <el-container>
        <el-header>
          <h3>{{info.username}}</h3>
          <el-button @click="logout()">退出登录</el-button>
        </el-header>
        <el-main>
          <!--  面包屑 -->
          <el-breadcrumb separator="/"  v-if="$route.meta.title"  class="mianbao">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>
              <a href="/">{{$route.meta.title}}</a>
            </el-breadcrumb-item>
            
          </el-breadcrumb>
          <!-- 二级路由出口 -->
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import {mapGetters,mapActions} from "vuex";
export default {
  computed:{
    ...mapGetters({
      info:"info"
    })
  },
  methods:{
    ...mapActions({
      changeInfo:"changeInfo"
    }),
    //退出登录
    logout(){
      this.changeInfo({})
      this.$router.push("/login")
    }
  }
};
</script >


<style lang="less" scoped>
@import "../../less/index.less";
.el-container {
  height: 100vh;
}
.el-aside {
  background: @primary;
}
.el-menu-item:focus,
.el-menu-item:hover,
/deep/.el-submenu__title:hover {
  background-color: @primary2;
}
.el-menu-item,
.el-submenu {
  background: @primary;
}

.el-header {
  background: @info;
}
</style>